home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / CONVERT.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  21KB  |  753 lines

  1. // CONVERT.CPP                                 1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. #define PROGRAM "CONVERT"  // Name of module
  11. /**************************************************************************/
  12.  
  13. #define MAX_LEVELS 10
  14.  
  15. typedef struct
  16. {
  17.     char summary;                   // Disk savings/time summary on/off
  18.     char keep_smallest;            // keep the smallest on/off
  19.     char keep_old;                   // keep the old archive ON/OFF/BENCH
  20.     char convert_old;               // convert old files of same type
  21.     char convert_non_optimal;       // convert non optimal files of same type
  22.     char convert_regardless;       // convert regardless.
  23.     char log_filename[FLENGTH];    // log_file
  24.     char log_append;               // log_append
  25.     char archive_type;               // type to convert to
  26.     char archive_ext[5];           // type to convert to extension
  27.     char recurse;                   // recurse on/off
  28.     int  num_convert;               // convert em all as default
  29.     int  threshold;                // If number to convert exceeds, then warn
  30.  
  31.     char ramdrive[FLENGTH];        // Ram Drive
  32.     long ramdrive_size;
  33.  
  34.     HANDLE log_file;               // Log file handle
  35.  
  36.     char before[FILE_SIZE];        // File Name before it changed
  37.  
  38.     long savings[MAX_TYPES];
  39.     long e_savings[MAX_TYPES];
  40.     int  b_per_sect;
  41.  
  42.     LISTPTR execute_before;
  43.     LISTPTR execute_during;
  44.     LISTPTR execute_after;
  45.  
  46.     long time_spent[MAX_TYPES];
  47.     long start_time;
  48.     long end_time;
  49.  
  50.     long files_processed;
  51.     long files_to_process;
  52.     long archives_not_processed;
  53.     BYTE erase_dest;
  54.  
  55.     LISTPTR paths[MAX_LEVELS];
  56. } CONVERT_INFO;
  57.  
  58. static int convert_process(AU *, char *, char *, char *, int);
  59.  
  60. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  61. static void get_relative_path(char *relative_path, char *sub_path,
  62.                               char *full_path)
  63. {
  64.     int len;
  65.     char sp[FLENGTH];
  66.     char fp[FLENGTH];
  67.  
  68.     strcpy(sp, sub_path);
  69.     strcpy(fp, full_path);
  70.  
  71.     append_backslash(sp);
  72.     append_backslash(fp);
  73.  
  74.     len = strlen(sp);
  75.     if (strnicmp(sp, fp, len) == 0)
  76.         strcpy(relative_path, fp+len);
  77.     else
  78.         strcpy(relative_path, fp);
  79.     return;
  80. }
  81. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  82. static long get_file_size(char *file_name)
  83. {
  84.     struct ffblk ffblk;           // directory entry structure
  85.     if (!findfirst(file_name, &ffblk, 0))
  86.         return ffblk.ff_fsize;
  87.     else
  88.         return 0;
  89. }
  90. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  91. static BYTE compare_extensions(char *file1, char *file2)
  92. {
  93.     char *ptr1, *ptr2;
  94.  
  95.     ptr1 = strchr(file1, '.');
  96.     ptr2 = strchr(file2, '.');
  97.     if (ptr1 == NULL && ptr2 == NULL)
  98.         return TRUE;
  99.     if (ptr1 == NULL && ptr2 != NULL)
  100.         return FALSE;
  101.     if (ptr1 != NULL && ptr2 == NULL)
  102.         return FALSE;
  103.     return (stricmp(ptr1, ptr2) == 0);
  104. }
  105. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  106. static void execute_list(AU *au, char *file_name, LISTPTR *listPtr)
  107. {
  108.     LIST *el;
  109.     char temp[CLENGTH];
  110.  
  111.     for (el = listPtr->head; el != NULL; el = el->next)
  112.     {
  113.         if (file_name == NULL)
  114.             strcpy(temp, el->data);
  115.         else
  116.             substitute_macros(temp, el->data, NULL, NULL, NULL, file_name);
  117.         execute_raw(au, temp);
  118. //          execute(au, temp, au->output, NULL, 0);
  119.     }
  120.     return;
  121. }
  122. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  123. static int convert_one(AU *au, char *sourceDir, char *destDir, LISTPTR *paths,
  124.                        char *file_name, int type, int level)
  125. {
  126.     char     temp_arc[FLENGTH];
  127.     char     new_arc[FLENGTH];
  128.     char     relative_path[FLENGTH];
  129.     char     temp[CLENGTH];
  130.     char     exec[CLENGTH];
  131.     char    *ptr;
  132.     int      retCode = 0;
  133.     PACKAGE *package;
  134.     LIST    *el;
  135.     long     old_size, new_size, temp_time1, temp_time2;
  136.     struct     ftime ftime_hold;
  137.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  138.  
  139.     package = &au->package[type];
  140.  
  141.     build_fname(temp_arc, sourceDir, "AU94.");
  142.     strcat(temp_arc, package->extension);
  143.  
  144.     strcpy(temp, file_name);
  145.     ptr = strchr(temp, '.');
  146.     if (ptr != NULL)
  147.         *ptr = '\0';
  148.     build_fname(new_arc, sourceDir, temp);
  149.     strcat(new_arc, ".");
  150.     strcat(new_arc, package->extension);
  151.  
  152.     substitute_macros(temp, package->arc, NULL,
  153.          au->unarc_paths == ON ? package->arc_path : package->arc_no_path,
  154.          NULL, temp_arc);
  155.  
  156.     cd(au, destDir);
  157.     execute_list(au, NULL, &in->execute_during);
  158.  
  159.     for (el = paths->head; el != NULL; el = el->next)
  160.     {
  161.         get_relative_path(relative_path, destDir, el->data);
  162.         if (relative_path[0] != '\0')
  163.             append_backslash(relative_path);
  164.         sprintf(exec, "%s %s*.*", temp, relative_path);
  165.         if (!au->no_extra)
  166.             au_printf(au, "    @?6Adding @?B%s*.* @?6to @?1%s@?H\n", relative_path, new_arc);
  167.         if (!au->simulate)
  168.         {
  169.             time(&temp_time1);
  170.             retCode = execute(au, exec, au->output, NULL, package->memoryNeeded);
  171.             time(&temp_time2);
  172.             in->time_spent[0] += temp_time2-temp_time1;
  173.  
  174.             if (retCode != 0)
  175.                 break;
  176.         }
  177.     }
  178.     cd(au, sourceDir);
  179.     if (retCode == 0)
  180.     {
  181.         if (au->date_retain == ON)
  182.             get_file_time(au, file_name, &ftime_hold);
  183.  
  184.         old_size = get_file_size(file_name);
  185.         new_size = get_file_size(temp_arc);
  186.  
  187.         if (in->keep_smallest == ON)
  188.         {
  189.             if (old_size < new_size)
  190.             {
  191.                 unlink(temp_arc);
  192.                 return 0;
  193.             }
  194.         }
  195.  
  196.         if (in->keep_old == OFF || compare_extensions(file_name, new_arc))
  197.             unlink(file_name);                            /* Delete old */
  198.  
  199.         rename(temp_arc, new_arc);       /* Rename AU94.xxx to file_name.xxx */
  200.  
  201.         if (au->date_retain == ON)
  202.             set_file_time(au, new_arc, &ftime_hold);
  203.         else if (au->date_retain != OFF)
  204.             redate_file(au, new_arc);
  205.  
  206.         in->savings[0]+=old_size - new_size;
  207.         in->e_savings[0]+=(old_size+in->b_per_sect-(old_size % in->b_per_sect)) -
  208.                           (new_size+in->b_per_sect-(new_size % in->b_per_sect));
  209.  
  210.         if (level == 0)
  211.         {
  212.             split_file(new_arc, temp, temp);
  213.             fix_flist(au, file_name, temp);
  214.         }
  215.         execute_list(au, new_arc, &in->execute_after);
  216.  
  217.     }
  218.  
  219.     return 0;
  220. }
  221. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  222. static int recurse(AU *au, char *path, int level)
  223. {
  224.     struct ffblk ffblk;           // directory entry structure
  225.     LISTPTR file_list;
  226.     LIST *el;
  227.     char holdCurDir[FLENGTH];
  228.     char curDir[FLENGTH];
  229.     char destDir[FLENGTH];
  230.  
  231.     cd(au, path, holdCurDir);
  232.     getcwd(curDir, FLENGTH);
  233.     build_fname(destDir, curDir, TEMP_DIR);
  234.     mkdir(TEMP_DIR);
  235.  
  236.     if (!findfirst("*.*", &ffblk, 0))
  237.     {
  238.         do
  239.         {
  240.             file_list.add(ffblk.ff_name);
  241.         }  while (!findnext(&ffblk));
  242.     }
  243.  
  244.     for (el = file_list.head; el != NULL; el = el->next)
  245.     {
  246.          if (convert_process(au, path, destDir, el->data, level) < 0)
  247.             return -1;
  248.     }
  249.     file_list.destroy();
  250.     cd(au, curDir, NULL);
  251.     rmdir(TEMP_DIR);
  252.     cd(au, holdCurDir, NULL);
  253.     return 0;
  254. }
  255. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  256. static int convert_process(AU *au, char *sourceDir, char *destDir,
  257.                            char *file_name, int level)
  258. {
  259.     LIST      *el;
  260.     int        retCode = 0;
  261.     int        type;
  262.     int        optimal, old;
  263.     ARC_HANDLE arc_handle;
  264.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  265.  
  266.     if (!ok_to_process(au, file_name))
  267.         return 0;
  268.  
  269.     /***************************************************/
  270.     cd(au, sourceDir);     /* Added 11/11/94 */
  271.  
  272.     arc_handle.init(au, file_name);
  273.     if (in->archive_type == 0)
  274.         type = arc_handle.type;
  275.     else
  276.         type = in->archive_type;
  277.  
  278.     /* Don't convert .GIFs yet */
  279.     if (arc_handle.type == GIF87 || arc_handle.type == GIF89)
  280.         arc_handle.type = NONARC;
  281.  
  282.     if (arc_handle.type > 0 && arc_handle.type == type &&
  283.         in->convert_regardless == OFF)
  284.     {
  285.         optimal = arc_handle.archive_is_optimal(au, file_name);
  286.         arc_handle.deinit(au);
  287.         if (optimal < 0)
  288.             return -1;
  289.         old = archive_is_old(arc_handle.version);
  290.         if (in->convert_old == OFF)
  291.         {
  292.             in->archives_not_processed++;
  293.             return 0;
  294.         }
  295.         if (!old && (optimal || !in->convert_non_optimal))
  296.         {
  297.             in->archives_not_processed++;
  298.             return 0;
  299.         }
  300.     }
  301.     else
  302.         arc_handle.deinit(au);
  303.  
  304.     if (arc_handle.type == 0)
  305.         return 0;
  306.     /***************************************************/
  307.  
  308.     execute_list(au, file_name, &in->execute_before);
  309.  
  310.     if (level == 0)
  311.     {
  312.         if (!au->no_extra)
  313.         {
  314.             au_printf(au, "@?6Converting @?1%s@?H ", file_name);
  315.             version_print(au, arc_handle.version, 9, TRUE);
  316.             if (!old && !optimal)
  317.                 au_printf_c(au, 11, " (Non Optimal)");
  318.             au_printf(au, " (%ld/%ld)\n", in->files_processed,
  319.                       in->files_to_process);
  320.         }
  321.         act_log_printf(au, "   + CONVERT : %s", file_name);
  322.  
  323.         au->number_processed++;
  324.     }
  325.     if (!au->self_extracts && arc_handle.is_self == TRUE)
  326.         return 0;
  327.  
  328.     if (unarc(au, file_name, destDir, &in->paths[level], 0, FALSE) == TRUE)
  329.     {
  330.         in->paths[level].add(destDir);
  331.         for (el = in->paths[level].head; el != NULL; el = el->next)
  332.         {
  333.             if (in->recurse == ON && level < MAX_LEVELS-1)
  334.             {
  335.                 if (recurse(au, el->data, level+1) != 0)
  336.                 {
  337.                     retCode = -1;
  338.                     break;
  339.                 }
  340.             }
  341.         }
  342.         retCode = convert_one(au, sourceDir, destDir, &in->paths[level], file_name, type,
  343.                               level);
  344.     }
  345.     clean_paths(au, &in->paths[level]);
  346.     return retCode;
  347. }
  348. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  349. static int convert(AU *au, char *file_name)
  350. {
  351.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  352.  
  353.     check_for_key();
  354.  
  355.     in->files_processed++;
  356.     return convert_process(au, au->source_directory, au->dest_directory,
  357.                            file_name, 0);
  358. }
  359. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  360. static void ReadCFGInfo(AU *au, CFG_HANDLE *cfg_handle)
  361. {
  362.     char string[200],
  363.          string2[200],
  364.          string3[200];
  365.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  366.  
  367.     for(EVER)
  368.     {
  369.         if (cfg_handle->read_line(au, string)==EOF)
  370.             break;
  371.  
  372.         split_string(string, string2);
  373.         split_string(string, string3);
  374.  
  375.         if (string2[0] == '\0')
  376.             continue;
  377.  
  378.         strcpy(au->curOpt, string2);
  379.         au->curVal = string3;
  380.         switch (toupper(string2[1]) << 8 | toupper(string2[0]))
  381.         {
  382.             case 'BE':                                          // Begin
  383.                 return;
  384.             case 'AR':                                          // Archive_Type
  385.                 if (isdigit(string[0]))
  386.                     in->archive_type = atoi(string);
  387.                 else
  388.                     safe_string_copy(in->archive_ext, string3, 5, FALSE);
  389.                 break;
  390.             case 'CO':                                          // Convert_Old
  391.                 if (stricmp(string2, "CONVERT_OLD") == 0)
  392.                     in->convert_old = get_value(au, OFF | ON);
  393.                 else if (stricmp(string2, "CONVERT_NON_OPTIMAL") == 0)                                           // Convert_non
  394.                     in->convert_non_optimal = get_value(au, OFF | ON);
  395.                 else
  396.                     in->convert_regardless = get_value(au, OFF | ON);
  397.                 break;
  398.             case 'DA':                                          // Date_Retain
  399.                 au->date_retain = get_value(au, OFF | ON | FIRST | LAST);
  400.                 break;
  401.             case 'DO':                                          // Dont_process
  402.                 au->dont_touch.add(string3);
  403.                 break;
  404.             case 'EX':                                          // Execute
  405.                 if (stricmp(string2, "EXECUTE_BEFORE") == 0)
  406.                 {
  407.                     sprintf(string2, "%s %s", string3, string);
  408.                     in->execute_before.add(string2);
  409.                 }
  410.                 else if (stricmp(string2, "EXECUTE_DURING") == 0)
  411.                 {
  412.                     sprintf(string2, "%s %s", string3, string);
  413.                     in->execute_during.add(string2);
  414.                 }
  415.                 else
  416.                 {
  417.                     sprintf(string2, "%s %s", string3, string);
  418.                     in->execute_after.add(string2);
  419.                 }
  420.             case 'KE':                                          // Keep_old
  421.                 if (stricmp(string2,"keep_old") == 0)
  422.                     in->keep_old = get_value (au, OFF | ON | BENCH);
  423.                 else if (stricmp(string2,"keep_smallest") == 0)
  424.                     in->keep_smallest = get_value (au, OFF | ON);
  425.                 break;
  426.             case 'LO':                                          // Log_File
  427.                 if (stricmp(string3,"+append")==0)
  428.                 {
  429.                     split_string(string,string3);
  430.                     in->log_append = TRUE;
  431.                 }
  432.                 else
  433.                     in->log_append = FALSE;
  434.  
  435.                 if (!strstr(string3,":") && !strstr(string3,"\\"))
  436.                 {
  437.                     strcpy(in->log_filename, au->cur_directory);
  438.                     append_backslash(in->log_filename);
  439.                 }
  440.                 else
  441.                     in->log_filename[0] = '\0';
  442.  
  443.                 strcat(in->log_filename, string3);
  444.                 break;
  445.             case 'PA':                                          // Paths
  446.                 au->unarc_paths = get_value(au, OFF | ON);
  447.                 break;
  448.             case 'RA':                                          // Ram_drive
  449.                 strcpy(in->ramdrive, string3);
  450.                 break;
  451.             case 'RE':                                          // Recurse
  452.                 in->recurse = get_value(au, OFF | ON);
  453.                 break;
  454.             case 'SE':                                          // Self_extract
  455.                 au->self_extracts = get_value(au, OFF | ON);
  456.                 break;
  457.             case 'SU':                                          // Summary
  458.                 in->summary = get_value(au, OFF | ON);
  459.                 break;
  460.             case 'TH':                                          // Threshold
  461.                 in->threshold = atoi(string3);
  462.                 break;
  463.             case 'WA':
  464.                 if (stricmp(string2, "WARN_NON_DOS")==0)
  465.                     au->warn_non_dos = get_value(au, OFF | ON | SKIP);
  466.                 else if (stricmp(string2, "WARN_PATH") == 0)
  467.                     au->warn_path = get_value(au, OFF | ON | SKIP);
  468.                 else
  469.                     au->warn_hidden = get_value(au, OFF | ON | SKIP);
  470.                 break;
  471.             case 'WO':                                          // Work_directory
  472.                 strcpy(au->dest_directory, string3);
  473.                 break;
  474.             default:
  475.                 cfg_handle->invalid_option(au, string2);
  476.         }
  477.     }
  478. }
  479. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  480. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  481.                             PARSE_TYPE type)
  482. {
  483.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  484.  
  485.     switch (type)
  486.     {
  487.     case PARSE_PARAM_OPTION:
  488.         switch (option)
  489.         {
  490.         case 'A':
  491.             in->archive_type = 0;
  492.             in->archive_ext[0] = '\0';
  493.             if (isdigit(cur_argv[0]))
  494.                 in->archive_type = atoi(cur_argv);
  495.             else
  496.                 safe_string_copy(in->archive_ext, cur_argv, 5, FALSE);
  497.             break;
  498.         case 'D':                 /* Delete behind on/off */
  499.             au->date_retain = get_value(au, OFF | ON | FIRST | LAST);
  500.             break;
  501.         case 'R':                 /* Recursive on/off */
  502.             in->recurse = get_value(au, OFF | ON);
  503.             break;
  504.         case 'U':
  505.             in->summary = get_value(au, OFF | ON);
  506.             break;
  507.         case 'X':
  508.             au->self_extracts = get_value(au, OFF | ON);
  509.             break;
  510.         case 'K':
  511.             if (toupper(*cur_argv) == 'S')
  512.             {
  513.                 strcpy(au->curOpt, "-KS");
  514.                 au->curVal = cur_argv+1;
  515.                 in->keep_smallest = get_value(au, OFF | ON);
  516.             }
  517.             else if (toupper(*cur_argv) == 'O')
  518.             {
  519.                 strcpy(au->curOpt, "-KO");
  520.                 au->curVal = cur_argv+1;
  521.                 in->keep_old = get_value(au, OFF | ON);
  522.             }
  523.             break;
  524.         case 'V':
  525.             if (toupper(*cur_argv) == 'O')
  526.             {
  527.                 strcpy(au->curOpt, "-VO");
  528.                 au->curVal = cur_argv+1;
  529.                 in->convert_old = get_value(au, OFF | ON);
  530.             }
  531.             else if (toupper(*cur_argv) == 'N')
  532.             {
  533.                 strcpy(au->curOpt, "-VN");
  534.                 au->curVal = cur_argv+1;
  535.                 in->convert_non_optimal = get_value(au, OFF | ON);
  536.             }
  537.             else if (toupper(*cur_argv) == 'R')
  538.             {
  539.                 strcpy(au->curOpt, "-VR");
  540.                 au->curVal = cur_argv+1;
  541.                 in->convert_regardless = get_value(au, OFF | ON);
  542.             }
  543.             else if (toupper(*cur_argv) == 'H')
  544.             {
  545.                 strcpy(au->curOpt, "-WH");
  546.                 au->curVal = cur_argv+1;
  547.                 au->warn_hidden = get_value(au, OFF | ON | SKIP);
  548.             }
  549.             break;
  550.         case 'P':
  551.             if (toupper(*cur_argv) == 'A')
  552.             {
  553.                 strcpy(au->curOpt, "-PA");
  554.                 au->curVal = cur_argv+1;
  555.                 au->unarc_paths = get_value(au, OFF | ON);
  556.             }
  557.             break;
  558.         case 'N':
  559.             in->num_convert    = atoi(cur_argv);
  560.             break;
  561.         case 'W':
  562.             if (toupper(*cur_argv) == 'P')
  563.             {
  564.                 strcpy(au->curOpt, "-WP");
  565.                 au->curVal = cur_argv+1;
  566.                 au->warn_path = get_value(au, OFF | ON | SKIP);
  567.             }
  568.             else if (toupper(*cur_argv) == 'N')
  569.             {
  570.                 strcpy(au->curOpt, "-WN");
  571.                 au->curVal = cur_argv+1;
  572.                 au->warn_non_dos = get_value(au, OFF | ON | SKIP);
  573.             }
  574.             break;
  575.         case 'L':
  576.            if (cur_argv[0] == '+')
  577.            {
  578.               cur_argv++;
  579.               in->log_append = TRUE;
  580.            }
  581.            else
  582.               in->log_append = FALSE;
  583.  
  584.            if (!strstr(cur_argv,":") && !strstr(cur_argv,"\\"))
  585.            {
  586.               strcpy(in->log_filename, au->cur_directory);
  587.               append_backslash(in->log_filename);
  588.            }
  589.            else
  590.               in->log_filename[0] = '\0';
  591.  
  592.            strcat(in->log_filename, cur_argv);
  593.            break;
  594.         case '?':
  595.             au_syntax_message(au, "Convert");
  596.             au_printf(au,
  597.                "[@?3options@?H] [@?1[src path\\]filespec@?H]\n\n");
  598.             au_param_heading(au);
  599.             au_printf(au,
  600.                "@?3-A@?Hn                  use Archiving type (number or ext)\n"
  601.                "@?3-D@?Hon|off|last|first  Date_retain\n"
  602.                "@?3-R@?Hon|off             Recurse\n"
  603.                "@?3-KO@?Hon|off            Keep Old archive if of different extension\n"
  604.                "@?3-KS@?Hon|off            Keep Smallest\n"
  605.                "@?3-X@?Hon|off             convert self eXtracts\n"
  606.                "@?3-VO@?Hon|off            convert Old archives of same type\n"
  607.                "@?3-VN@?Hon|off            convert Non optimal archives of same type\n"
  608.                "@?3-VR@?Hon|off            convert Regardless\n"
  609.                "@?3-WP@?Hon|off|skip       Warn if archive contains Paths\n"
  610.                "@?3-WN@?Hon|off|skip       Warn if archive contains Non-DOS file names\n"
  611.                "@?3-WH@?Hon|off|skip       Warn if archive contains Hidden or system files\n"
  612.                "@?3-N@?Hx                  x Number of converts before halting\n"
  613.                "@?3-U@?Hon|off             sUmmary\n"
  614.                "@?3-L@?H[+]<File>          Log file\n");
  615.             exit (0);
  616.         default:
  617.             au_invalid_option(au, PROGRAM, option);
  618.         }
  619.         return TRUE;
  620.     case PARSE_POST_CHECK:
  621.         /* Must delay search until whole .cfg is parsed */
  622.         if (in->archive_ext[0] != '\0')
  623.             in->archive_type = find_ext(au, in->archive_ext);
  624.         return TRUE;
  625.     }
  626.     return FALSE;
  627. }
  628. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  629. static void summary(AU *au)
  630. {
  631.     CONVERT_INFO *in = (CONVERT_INFO *)au->info;
  632.     int num_arcs = 1;
  633.     int i;
  634.     int e_mins, e_secs;
  635.     long elapsed_time;
  636.  
  637.     if (!au->no_extra)
  638.     {
  639.         au_printf(au, "@?7");
  640.  
  641.         au_printf(au, "\nConversion Summary:\n");
  642.         au_printf(au, "+========+==========+============+==========+\n");
  643.         au_printf(au, "|  Arc   | Savings  | Effective  |   Time   |\n");
  644.         au_printf(au, "| Method | in bytes |  Savings   | Min:Sec  | \n");
  645.         au_printf(au, "+========+==========+============+==========+\n");
  646.  
  647.         for (i=0; i<num_arcs; i++)
  648.         {
  649.             e_mins = in->time_spent[i]/60;
  650.             e_secs = in->time_spent[i]-e_mins*60;
  651.  
  652.             au_printf(au, "|  %3s   | ", au->package[in->archive_type].extension);
  653.             au_printf(au, "%8ld | %8ld   |  ", in->savings[i], in->e_savings[i]);
  654.             au_printf(au, "%3d:%02d  |\n", e_mins, e_secs);
  655.             if (i < num_arcs-1)
  656.                 au_printf(au, "|--------+----------+------------+----------+\n");
  657.         }
  658.         au_printf(au, "+========+==========+============+==========+\n");
  659.         elapsed_time = in->end_time - in->start_time;
  660.         e_mins = elapsed_time/60;
  661.         e_secs = elapsed_time-e_mins*60;
  662.         au_printf(au, "Total Elapsed time = %d:%02d\n", e_mins, e_secs);
  663.         au_printf(au, "Files Converted = %d\n", au->number_processed);
  664.         if (in->archives_not_processed > 0)
  665.         {
  666.             au_printf(au, "Files that didn't need to be converted = %ld\n",
  667.                         in->archives_not_processed);
  668.         }
  669.         au_printf(au, "@?G");
  670.     }
  671. }
  672. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  673. static void end_program(void)
  674. {
  675.     CONVERT_INFO *in = (CONVERT_INFO *)glob_au->info;
  676.     int i;
  677.  
  678.     for (i=MAX_LEVELS-1; i>=0; i--)
  679.     {
  680.         /* Remove any left over paths if dearchive failes */
  681.         clean_paths(glob_au, &in->paths[i]);
  682.     }
  683.     if (in->erase_dest)
  684.     {
  685.         cd(glob_au, glob_au->dest_directory);
  686.         execute_raw(glob_au, "echo Y | del *.* >NUL");
  687.         cd(glob_au, glob_au->cur_directory);
  688.         rmdir(glob_au->dest_directory);
  689.     }
  690.     return;
  691. }
  692. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  693. int main_convert(AU *au, int argc, char *argv[])
  694. {
  695.     int   i;
  696.     int   fh;
  697.     CONVERT_INFO *in;
  698.     struct dfree dfree;
  699.  
  700.     in = new CONVERT_INFO;
  701.     memset(in, '\0', sizeof(CONVERT_INFO));
  702.     au->info = in;
  703.     in->num_convert   = -1;
  704.     in->threshold      = -1;
  705.     in->archive_type  = 0;
  706.     in->keep_old      = OFF;
  707.     in->keep_smallest = OFF;
  708.  
  709.     au->allow_rename  = FALSE;
  710.     au->recurse       = OFF;           /* For Unarc's sake */
  711.  
  712.     atexit(end_program);
  713.  
  714.     time(&in->start_time);
  715.  
  716.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
  717.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  718.  
  719.     if (au->dest_directory[0] != '\0')
  720.     {
  721.         cd(au, au->dest_directory, au->old_dest_dir);     /* make sure it exists */
  722.         getcwd(au->dest_directory, FLENGTH);
  723.         cd(au, au->cur_directory);
  724.     }
  725.     else
  726.         build_fname(au->dest_directory, au->cur_directory, TEMP_DIR);
  727.  
  728.     in->files_to_process = check_threshold(au, in->threshold, FALSE);
  729.  
  730.     if (in->archive_type == 0)
  731.     {
  732.         au_printf_c(au, 15, "Files will retain their existing archive type\n");
  733.         if (!ask_continue())
  734.             exit(0);
  735.     }
  736.  
  737.     getdfree(0, &dfree);
  738.     in->b_per_sect = dfree.df_bsec;
  739.  
  740.     mkdir(au->dest_directory);
  741.     in->erase_dest = TRUE;
  742.     process_files(au, convert);
  743.     rmdir(au->dest_directory);
  744.     in->erase_dest = FALSE;
  745.  
  746.     time(&in->end_time);
  747.     if (summary)
  748.         summary(au);
  749.  
  750.     return 0;
  751. }
  752.  
  753.